﻿using SqlSugar;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Linq.Expressions;
using System.Text;
using System.Threading.Tasks;

namespace IService
{
    public interface IBaseService<T> where T : class, new()
    {
        #region 同步
    
        /// <summary>
        /// 查找 -通过id
        /// </summary>
        /// <param name="id"></param>
        /// <returns></returns>
        public T Find(string id);

        /// <summary>
        /// 根据条件获取实体对象
        /// </summary>
        /// <param name="whereLambda"></param>
        /// <returns></returns>
        public T Query(Expression<Func<T, bool>> whereLambda);

        /// <summary>
        /// 根据条件获取实体对象集合
        /// </summary>
        /// <param name="whereLambda"></param>
        /// <returns></returns>
        public List<T> QueryList(Expression<Func<T, bool>> whereLambda);
        /// <summary>
        /// 根据条件获取实体对象集合 包括删除数据
        /// </summary>
        /// <param name="whereLambda"></param>
        /// <returns></returns>
        public List<T> QueryListIncludeDelete(Expression<Func<T, bool>> whereLambda);
        /// <summary>
        /// 根据条件获取实体对象集合分页
        /// </summary>
        /// <param name="whereLambda"></param>
        /// <param name="pageIndex"></param>
        /// <param name="pageSize"></param>
        /// <param name="orderbyWhere"></param>
        /// <param name="orderByType"></param>
        /// <returns></returns>
        public (List<T>, int) QueryList(Expression<Func<T, bool>> whereLambda, int pageIndex, int pageSize, Expression<Func<T, object>> orderbyWhere, OrderByType orderByType);
        /// <summary>
        /// 新增
        /// </summary>
        /// <param name="entity"></param>
        /// <returns></returns>
        public T AddBackEntity(T entity);
        /// <summary>
        /// 新增
        /// </summary>
        /// <param name="entity"></param>
        /// <returns></returns>
        public bool Add(T entity);

        /// <summary>
        /// 修改
        /// </summary>
        /// <param name="entity"></param>
        /// <returns></returns>
        public bool Update(T entity);
        /// <summary>
        /// 删除 根据条件
        /// </summary>
        /// <param name="whereLambda"></param>
        /// <returns></returns>
        public bool DeleteByWhere(Expression<Func<T, bool>> whereLambda);
        /// <summary>
        /// 删除
        /// </summary>
        /// <param name="entity"></param>
        /// <returns></returns>
        public bool Dellete(T entity);

        /// <summary>
        /// 查看列表-缓存
        /// </summary>
        /// <returns></returns>
        public List<T> GetListCache();

        #endregion

        #region 异步
  
        /// <summary>
        /// 查找 -通过id
        /// </summary>
        /// <param name="id"></param>
        /// <returns></returns>
        public Task<T> FindAsync(string id);

        /// <summary>
        /// 根据条件获取实体对象
        /// </summary>
        /// <param name="whereLambda"></param>
        /// <returns></returns>
        public Task<T> QueryAsync(Expression<Func<T, bool>> whereLambda);

        /// <summary>
        /// 根据条件获取实体对象集合
        /// </summary>
        /// <param name="whereLambda"></param>
        /// <returns></returns>
        public Task<List<T>> QueryListAsync(Expression<Func<T, bool>> whereLambda);
        /// <summary>
        /// 根据条件获取实体对象集合 包括删除数据
        /// </summary>
        /// <param name="whereLambda"></param>
        /// <returns></returns>
        public Task<List<T>> QueryListIncludeDeleteAsync(Expression<Func<T, bool>> whereLambda);
        /// <summary>
        /// 根据条件获取实体对象集合分页
        /// </summary>
        /// <param name="whereLambda"></param>
        /// <param name="pageIndex"></param>
        /// <param name="pageSize"></param>
        /// <param name="orderbyWhere"></param>
        /// <param name="orderByType"></param>
        /// <returns></returns>
        public Task<(List<T>, int)> QueryListAsync(Expression<Func<T, bool>> whereLambda, int pageIndex, int pageSize, Expression<Func<T, object>> orderbyWhere, OrderByType orderByType);
        /// <summary>
        /// 新增
        /// </summary>
        /// <param name="entity"></param>
        /// <returns></returns>
        public Task<T> AddBackEntityAsync(T entity);
        /// <summary>
        /// 新增
        /// </summary>
        /// <param name="entity"></param>
        /// <returns></returns>
        public Task<bool> AddAsync(T entity);

        /// <summary>
        /// 修改
        /// </summary>
        /// <param name="entity"></param>
        /// <returns></returns>
        public Task<bool> UpdateAsync(T entity);
        /// <summary>
        /// 删除 根据条件
        /// </summary>
        /// <param name="whereLambda"></param>
        /// <returns></returns>
        public Task<bool> DeleteByWhereAsync(Expression<Func<T, bool>> whereLambda);
        /// <summary>
        /// 删除
        /// </summary>
        /// <param name="entity"></param>
        /// <returns></returns>
        public Task<bool> DelleteAsync(T entity);

        /// <summary>
        /// 查看列表-缓存
        /// </summary>
        /// <returns></returns>
        public Task<List<T>> GetListCacheAsync();

        #endregion
    }
}
